package ck.android.englishschool;

import java.util.ArrayList;
import java.util.Random;

import android.app.Application;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.widget.EditText;
import ck.android.englishschool.util.BrHttpManager;
import ck.android.englishschool.util.BrUtilManager;
import ck.android.englishschool.vo.MemberVO;
import ck.android.englishschool.vo.WordDetailVO;
import ck.android.englishschool.vo.WordListVO;

public class AppStatus extends Application{
	public ProgressDialog dialog;					//다이얼로그
	
	public BrUtilManager utilm = null;
	public BrHttpManager httpm = null;
	
	public MemberVO memberVo; 						//로그인정보를 담는다.
	
	private boolean endApp;							//어플리케이션 종료 값
	
	//리스트 아이템들...
	private ArrayList<WordListVO> arrWordList;
	private ArrayList<WordDetailVO> arrWordDetail;
	
	@Override
	public void onCreate() {
		super.onCreate();
		Log.i("create Application", "create Application.....");
		utilm = BrUtilManager.getInstance();
	    httpm = BrHttpManager.getInstance();
	}
	
	/*공통 메서드*/
	
	//널체크를 하여 메세지를 출력한다.
	public boolean checkInval(Context context, EditText editText, String name){
		boolean val = true;
		EditText et = new EditText(context);
		et = editText;
		if(null==et.getText().toString()||"".equals(et.getText().toString())){
			utilm.ShowDialog(context, "실패", name + " 을/를 넣어 주세요.", 20);
			et.setFocusable(true);
			val = false;
		}
		
		return val;
	}
	
	//단어를 섞는 메서드
	public ArrayList<WordDetailVO> shuffleWord(ArrayList<WordDetailVO> lvo){
		ArrayList<WordDetailVO> rlvo = lvo;
		
		int totalSize = rlvo.size();
		Random r = new Random();
		int ran = r.nextInt();
		WordDetailVO svo = null;
		WordDetailVO rvo = null;
		
		System.out.println("1."+arrWordDetail.toString());
		rlvo.get(0).setkWord("뭐야");
		for(int i=0 ; i<totalSize; i++){
			ran = r.nextInt(totalSize);
			svo = rlvo.get(ran);
			rvo = rlvo.get(i);
			rlvo.set(ran, rvo);
			rlvo.set(i, svo);
		}
		System.out.println("2."+arrWordDetail.toString());
		
		return rlvo;
	}
	
	//프로그래스 다이얼 로그
	public void showDialogNo(String message, Context context) {
	dialog = new ProgressDialog(context);
	dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
	dialog.setMessage(message);
	dialog.setIndeterminate(true);
	dialog.setCancelable(false);
	dialog.show();
	}

	/*getter & setter*/
	
	public MemberVO getMemberVo() {
		return memberVo;
	}

	public void setMemberVo(MemberVO memberVo) {
		this.memberVo = memberVo;
	}
	
	public boolean isEndApp() {
		return endApp;
	}

	public void setEndApp(boolean endApp) {
		this.endApp = endApp;
	}
	

	public ArrayList<WordListVO> getArrWordList() {
		return arrWordList;
	}

	public void setArrWordList(ArrayList<WordListVO> arrWordList) {
		this.arrWordList = arrWordList;
	}
	

	public ArrayList<WordDetailVO> getArrWordDetail() {
		return arrWordDetail;
	}

	public void setArrWordDetail(ArrayList<WordDetailVO> arrWordDetail) {
		this.arrWordDetail = arrWordDetail;
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		Log.i("Terminate Application", "Terminate Application.....");
	}
	
}
